package com.gitee.wsl.common.ui.input.event

import com.gitee.wsl.common.ui.base.Point
import com.gitee.wsl.common.ui.input.KEventListener
import com.gitee.wsl.common.ui.input.emptyListener

data class KPointer(
    val id: Int,
    val pos: Point
)

/**
 * The Pointer Event interface.
 * Extends [HasMetaKeys]
 *
 * @property pos The position of the pointer
 * @property eventType The type of the event as an [EventType]
 * @property pointerType The type of the pointer as a [PointerType]
 * @property buttonPressed The button pressed when using a mouse, else MouseButtonPressed.NotApplicable
 * @property activePointerIndex The index of the pointer that triggers the event, in case of a multitouch
 * @property pointers The index-ordered list of all pointers (including this one) as [KPointer], useful for multitouch
 */
 interface KPointerEvent: KEvent, HasMetaKeys {
     val pos: Point
     val eventType: EventType
     val pointerType: PointerType
     val buttonPressed: MouseButtonPressed
     val activePointerIndex: Int
     @OptIn(ExperimentalKEvent::class)
     val pointers: List<KPointer>
}

/**
 * Common Pointer event.
 */

internal open class KPointerEventImpl @OptIn(ExperimentalKEvent::class) constructor(
    override val pos: Point,
    override val eventType: EventType,
    override val pointerType: PointerType,
    override val buttonPressed: MouseButtonPressed,
    override val activePointerIndex: Int,
    override val pointers: List<KPointer>,
    altKey: Boolean,
    ctrlKey: Boolean,
    shiftKey: Boolean,
    metaKey: Boolean
) : KPointerEvent, HasMetaKeys by HasMetaKeysImpl(altKey, ctrlKey, shiftKey, metaKey) {

    override fun toString(): String = "KPointerEvent(pos=$pos)"
}

/**
 * Create a new listener for a given [EventType].
 **/
//internal expect fun pointerEventsListener(type: EventType): KEventListener<KPointerEvent>
fun pointerEventsListener(type: EventType): KEventListener<KPointerEvent> = emptyListener()